/*
 * Copyright (C) 2010, JDevelopers (jdevelopers@my-pages.org) 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 */
/**
 * Foo
 */
package org.jdevelopers.xarf.util;

/**
 * Factory, which creates the mapped Java-Classes for the classes in the JSON-schema.
 * 
 * @author Marcel Hartwig
 * @version 0.1
 * @since JXarfValidator 0.1
 */
public class ClassFactory {

	/**
	 * Private Constructor, because no public constructor is needed.
	 */
	private ClassFactory() {
	}
	
	/**
	 * Creates the mapped Java-Classes from the classes in the JSON-schema.
	 * 
	 * @param shortClassName short name of the class in JSON-schema
	 * @return representing Java-Class
	 * @throws ClassNotFoundException If there is a class given, that is unknown.
	 */
	public static Class<?> getClassFromName(String shortClassName) throws ClassNotFoundException {
		if(shortClassName == null) {
			throw new ClassNotFoundException(shortClassName);
		}
		if(shortClassName.equals("string")) {
			return java.lang.String.class;
		} else if(shortClassName.equals("integer")) {
			return java.lang.Integer.class;
		} else if(shortClassName.equals("number")) {
			return java.lang.Number.class;
		}
		throw new ClassNotFoundException(shortClassName);
	}
	
	/**
	 * Returns the long name for a class.
	 * 
	 * @param classType class, that should be checked.
	 * @return Name for the class.
	 * @throws ClassNotFoundException if a not supported class should be checked.
	 */
	public static String getClassName(Class<?> classType) throws ClassNotFoundException {
		if (classType.equals(Integer.class)) {
			return Integer.class.getName();
		} else if (classType.equals(Number.class)) {
			return Number.class.getName();
		} else if (classType.equals(String.class)) {
			return String.class.getName();
		}
		throw new ClassNotFoundException();
	}
	
}
